package com.younion.action.manage;

import java.io.ByteArrayInputStream;

import org.apache.struts2.ServletActionContext;

import com.younion.common.base.BaseAction;
import com.younion.common.util.RandomNumUtil;

/**
 * @Title: RandomCodeAction.java
 * @Package com.younion.action.manage
 * @author seagull
 * @date Sep 14, 2012 10:58:00 AM
 */

public class RandomCodeAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private ByteArrayInputStream inputStream;

	public String getRandomCode() throws Exception {
		RandomNumUtil rdnu = RandomNumUtil.Instance();
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/jpeg");
		setInputStream(rdnu.getImage());// 取得带有随机字符串的图片
		// 取得随机字符串放入HttpSession
		ServletActionContext.getRequest().getSession().setAttribute("random", rdnu.getString());
		return SUCCESS;
	}

	public void setInputStream(ByteArrayInputStream inputStream) {
		this.inputStream = inputStream;
	}

	public ByteArrayInputStream getInputStream() {
		return inputStream;
	}
}
